// by Xeno
//#define __DEBUG__
#define THIS_FILE "fn_sideairsteal.sqf"
#include "x_setup.sqf"
private ["_reached_base","_vehicle"];
if !(call FUNC(checkSHC)) exitWith {};

PARAMS_1(_vehicle);

sleep 10.213;

_reached_base = false;
#ifdef __TT__
_winner = 0;
#endif

while {alive _vehicle && {!_reached_base}} do {
	call FUNC(mpcheck);
#ifndef __TT__
	if (_vehicle distance GVAR(FLAG_BASE) < 300) then {_reached_base = true};
#else
	if (_vehicle distance GVAR(WFLAG_BASE) < 300) then {
		_reached_base = true;
		_winner = 2;
	} else {
		if (_vehicle distance GVAR(EFLAG_BASE) < 300) then {
			_reached_base = true;
			_winner = 1;
		};
	};
#endif
	sleep 5.2134;
};

if (alive _vehicle && {_reached_base}) then {
#ifndef __TT__
	GVAR(sm_winner) = 2;
#else
	GVAR(sm_winner) = _winner;
#endif
} else {
	GVAR(sm_winner) = -600;
};

GVAR(sm_resolved) = true;
if (GVAR(IS_HC_CLIENT)) then {
	[QGVAR(sm_var), GVAR(sm_winner)] call FUNC(NetCallEventCTS);
};